//document.getElementById

function htmlEncode(s)
{
	return escape(s);
	
}

var xmlhttp; 
var resultDiv;
var completed = false;

function batchSubmit(form)
{
	form = $(form);
	var elements = form.elements;
	for(var i=0; i<elements.length; i++)
	{
		try
		{
			if(elements[i].checked)
			{
				form.submit();
				return;
			}
		}
		catch(e){}
	}
	message("ALERT","ȫѡձׁʙһ͵¼Ȃ¼");
}

function loadXMLDoc2Div(url,div) 
{
	resultDiv = $(div);
	loadXMLDoc(url,state_Change);
}

function checkRequestResult(url)
{
	xmlhttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttpRequest.open("POST", url, false);
	xmlhttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttpRequest.send("");
	var text = xmlhttpRequest.responseText;
	if(text.indexOf("true")>=0)
	{
		return true;
	}
	else if(text.indexOf("false")>=0)
	{
		return false;
	}
}

function loadXMLDoc(url,f)
{
	if (window.ActiveXObject) 
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) 
		{
			xmlhttp.onreadystatechange = f;
			xmlhttp.open("POST", url, false);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlhttp.send("");
		}
	}
	else if (window.XMLHttpRequest)
	{  
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = state_Change;
		xmlhttp.open("POST", url, false);
		xmlhttp.send("");
	} 
}

function formSerializer(form)
{
	var myform = $(form);
	var val = "";
	var sendData = "";
	for (i=0;i<myform.elements.length;i++)
	{
		element = myform.elements[i]
		if(element.type && (element.type=="radio" || element.type=="checkbox"))
		{
			if(element.checked)
			{
				sendData += element.name + "=" + element.value + "&";
			}
		}
		else
		{
			val = element.value;

			if (element.type=="textarea"||element.type=="text")
			{
				val = htmlEncode(val);
			}
		
			sendData += element.name + "=" + val + "&";
		}
	}
	return sendData;
}

//submit form by XMLHttpRequest
function submitXMLDoc(myform,url,f) {
	var sendData = "";
	var val = "";
	var myform = $(myform)
	sendData = formSerializer(myform);
	if (window.ActiveXObject) 
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) 
		{
			xmlhttp.onreadystatechange = f;
			xmlhttp.open("POST", url, false);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
			xmlhttp.send(sendData);
		}
	}
	else if (window.XMLHttpRequest)
	{  
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = state_Change;
		xmlhttp.open("POST", url, false);
		xmlhttp.send(sendData);
	} 
	// code for IE 
}
//submit form by XMLHttpRequest and set response to a div
function submitXMLDoc2Div(myform,url,div) 
{
	resultDiv = $(div);
	submitXMLDoc(myform,url,state_Change);
}
//default XMLHttpRequest response function
function state_Change() {
	// if xmlhttp shows "loaded"
	if(xmlhttp.readyState < 4){
		resultDiv.innerHTML = "<br>loading...";
	}
	if (xmlhttp.readyState == 4) {
		completed = true;
		// if "OK"
		if (xmlhttp.status == 200) {
			resultDiv.innerHTML = xmlhttp.responseText;
		} else {
			resultDiv.innerHTML = "<br>error:"+xmlhttp.statusText;
		}
	}
}

function popupWindow(name,dictionary)
{
	getOptionList("<%=appPath%>/sample/businesstest/dictionaryTreeOrList.do?method=treeOrList&XT_TYKJ_KJMC=" + dictionary + "&inputKey=" + name + "&inputName=" + name + "_title");
}

function initOption(elementID,dictionary,value)
{
	initSelect(elementID,dictionary,"",value);
}

function initSelect(elementID,dictionary,condition,value)
{
	
	var list;
	if(dict_list.indexOf("," + dictionary + ",")>=0)
	{
		var s = eval("dict_"+dictionary);
		list = s.split(/[=;]/);
	}
	else
	{
		var xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		var url = "/public/dictionary/dictionarySelect.do?method=getQueryList&XT_TYKJ_KJMC=" + dictionary + "&change=null&CONDITION=" + condition + "&returnList=&returnInputList=&rootName=";
		xmlhttp.Open("POST",url,false);
		xmlhttp.send(null);
		var res=xmlhttp.responseText;
		var doc=new ActiveXObject("MSXML.DOMDocument");
		doc.async=false;
		doc.loadXML(res);
		var root = doc.documentElement;
		list = new Array();
		var oNodeList = root.childNodes;
		for (var i=0; i<oNodeList.length; i++) 
		{
		  	var Item = oNodeList.item(i);
		  	var dc=Item.childNodes;
		  	list[2*i] = dc[0].firstChild.xml;
		  	list[2*i+1] = dc[1].firstChild.xml;
		}
	}
	var defaultvalue = value;
	var element = $(elementID);
	
	if(element.value!="")
	{
		defaultvalue = element.value;
	}

	var strOption="<SELECT style='width:120px' NAME='" + elementID + "' origin='" + defaultvalue + "'/>";
	var op=document.createElement(strOption);
	op.options[0]=new Option("\u8BF7\u9009\u62E9","");
	var selectedText = defaultvalue;
	for(var i=0; i<list.length/2; i++)
	{
	 	op.options[i+1]=new Option(list[2*i+1],list[2*i]);
		if(list[2*i]==defaultvalue||list[2*i+1]==defaultvalue)
	    {
	        op.options[i+1].selected=true;
		}
	}
	if(!op.selectedIndex || op.selectedIndex<0)
	{
		op.selectedIndex=0;
		op.origin="";
	}
	if(page_type=="view" && element.tagName.toLowerCase()=="span")
	{
		var sText = "";
		if(op.selectedIndex && op.selectedIndex>0)
		{
			sText = op[op.selectedIndex].text;
		}
		element.innerText = sText;
	}
	else
	{
		p = element.parentNode;
		p.insertBefore(op,element);
		p.removeChild(element);
	}	
}
		
		
function addOptionToSelect(elementID,url,positionID,currentID){
	
	var xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp.Open("POST",url,false);
	xmlhttp.send(null);
	
	var res=xmlhttp.responseText;
	var doc=new ActiveXObject("MSXML.DOMDocument");
	doc.async=false;
	doc.loadXML(res);
	
	var root = doc.documentElement;
	
	var oNodeList = root.childNodes;
	
	var strOption="<SELECT NAME='"+elementID+"'/>";
	var op=document.createElement(strOption);
	op.options[0]=new Option("\u8BF7\u9009\u62E9","");
	for (var i=0; i<oNodeList.length; i++) 
	{
	  var Item = oNodeList.item(i);
	  var dc=Item.childNodes;
 	  op.options[i+1]=new Option(dc[1].firstChild.xml,dc[0].firstChild.xml);
	  if(dc[0].firstChild.xml==currentID)
      {
         op.options[i+1].selected=true;	
      }

	}

	document.all(positionID).appendChild(op);
}

function inputDisable(fields)
{
	var arr = fields.split(/[,]/);
	for(var i=0;i<arr.length;i++)
	{
		var element = document.all(arr[i]);
		try
		{
			if(element.type=="hidden")
			{
				element = document.all('c_' + element.name);//checkbox
				if(!element.length)
				{
					message("ALERT",arr[i] + "is hidden, you are crazy");
				}
			}
		}
		catch(e){}
		if(element.tagName && element.tagName.toUpperCase()=="SELECT")  //select
		{
			if(!element.origin)
			{
				element.origin = element.value;
			}
			element.onchange = reValueCheck;	
			element.className = "disable";
			element.onselectstart=returnFalse;
			element.onclick=returnFalse;
		}
		else if(element.type && element.type.toLowerCase()=="checkbox")//checkbox
		{
			element.onclick = reValueCheck;
		}
		else if(element.length && element.length>1) //radio and checkbox
		{
			for(var j=0; j<element.length; j++)
			{
				element[j].origin = element[j].checked;
				element[j].onclick = reValueCheck;
			}
		}
		else
		{
			try
			{
				element.readOnly = true;
				element.style.bgcolor="#E3EFF8";
				element.style.color="gray";
				element.onblur = returnFalse;
				element.onselectstart=returnFalse;
				try
				{
					if(element.nextSibling.outerHTML.indexOf("DateInputInner_onclick")>0)
					{
						element.parentNode.removeChild(element.nextSibling);
					}
				}
				catch(e){}
			}
			catch(e){}
		}
	}
}

function returnFalse()
{
	return false;
}

function getSelectText(element)
{
	element = $(element)
	var text = element.options[element.selectedIndex].text;
	if(element.selectedIndex==0 && element.value=="")
	{
		text = "";
	}
	return text;
}

	function elementSpy(element,value)
	{
		try
		{
			$("v_" + element.name).value = value;
		}
		catch(e){}	
	}

function input2text(fields)
{
	var arr = fields.split(/[,]/);
	var n = 0;
	var a = new Array();
	for(var i=0;i<arr.length;i++)
	{
		try
		{
			var element = $(arr[i]);
			try
			{
				//try dictcheckbox
				if(element.type=="hidden")
				{
					element = getInputSelector("c_" + element.name);
				}
				else if(!element || element.type.toLowerCase()=="radio")
				{
					element = getInputSelector(element.name);
				}
			}
			catch(e){}
			//text and select
			if(!element.length || element.tagName=="SELECT")
			{
				a[n++] = $(arr[i]);
				try
				{
					if(element.nextSibling.tagName=="IMG" || element.nextSibling.tagName=="A")
					{
						element.parentNode.removeChild(element.nextSibling);
					}
				}
				catch(e){}
			}
			else if(element.length && element.length>1)
			{
				for(var j=0;j<element.length;j++)
				{
					a[n++] = element[j];
				}
			}
		}catch(e){}
	}
	changeInputField(a);
}

function getInputSelector(name)
{
	var list = document.getElementsByTagName("INPUT");
	var arr = new Array();
	var n = 0;
	for(var i=0; i<list.length; i++)
	{
		if(list[i].name == name)
		{
			arr[n++] = list[i];
		}
	}
	return arr;
}

function initViewTable(table,row1,row2)
{
	var list = new Array();
	table = $(table);
	row_list = table.getElementsByTagName("tr");
	for(var i=row1; i<row2; i++)
	{
		appendArray(list,row_list[i].getElementByTagName("input"));
		appendArray(list,row_list[i].getElementByTagName("select"));
		appendArray(list,row_list[i].getElementByTagName("textarea"));
		appendArray(list,row_list[i].getElementByTagName("img"));
		deleteLink(row_list[i]);
	}
	changeInputField(list);
}

function deleteLink(div)
{
	div = $(div)
	list = div.getElementsByTagName("a");
	for(var i=list.length-1;i>=0;i--)
	{
		list[i].outerHTML = "";
	}
}
function appendArray(a,b)
{
	len = a.length;
	for(i=0; i<b.length; i++)
	{
		a[len+i]=b[i];
	}
}
function initViewPage(div)
{
	var p = document.body;
	if(div && document.all(div))
	{
		p = document.all(div)
	}
	changeInputField(p.getElementsByTagName("input"));
	changeInputField(p.getElementsByTagName("select"));
	changeInputField(p.getElementsByTagName("textarea"));
	changeImageField(p.getElementsByTagName("img"));
	list = p.getElementsByTagName("a");
	for(var i=list.length-1;i>=0;i--)
	{
		if(list[i].innerText != "\u8FD4\u56DE")
		{
			list[i].outerHTML = "";
		}
	}
	initDictCheckView(p);
}

function initDictCheckView(div)
{
	var	list = div.getElementsByTagName("checkspan");
	for(var i=list.length-1; i>=0; i--)
	{
		p = list[i].parentNode;
		while(p.tagName.toLowerCase()!="table")
		{
			p = p.parentNode;
		}
		p.outerHTML="<span id=" + list[i].id + ">" + list[i].value + "</span";
	}
}
function changeImageField(list)
{
	for(var i=list.length-1;i>=0;i--)
	{
		if(list[i].outerHTML.indexOf("DateInputInner_onclick")>0)
		{
			list[i].outerHTML = "";
		}
	}
}

function changeInputField(list)
{
	if(list.length<1)
	{
		return;
	}

	for(i=list.length-1;i>=0;i--)
	{
		var x=list[i];
		tag = x.tagName.toUpperCase();
		type = x.type.toUpperCase();

		if(tag=="TEXTAREA" || type=="TEXT")
		{
			x.outerHTML = "<span>" + x.value + "</span>";
		}
		else if(tag=="SELECT")
		{
			var text = getSelectText(x);
			x.outerHTML = "<span>" + text + "</span>";
		}
		else if(type == "CHECKBOX" || type == "RADIO")
		{
			var s = "";
			while(i>0 && list[i].name==x.name)
			{
				if(list[i].checked)
				{
					s = getCheckText(list[i]) + "," + s;
				}
				i--;
			}
			i++;
			if(s.length>0)
			{
				s = s.substring(0,s.length-1);
			}
			var p = x;
			if(x.name.indexOf("c_")==0)
			{
				p = x.parentNode;
				while(p.parentNode.tagName!="TD")
				{
					p = p.parentNode;
				}
			}
			p.parentNode.innerHTML = s;
		}	
		else if(tag=="IMG")
		{
			if(x.outerHTML.indexOf("DateInputInner_onclick")>0)
			{
				x.outerHTML = "";
			}
		}		
		removeNextActive(x);
	}
}

	function removeNextActive(x)
	{
		if(x.nextSibling && x.nextSibling.tagName)
		{
			var next = x.nextSibling.tagName.toUpperCase();
			while(next=="IMG" || next=="A")
			{
				x.parentNode.removeChild(x.nextSibling);
				if(x.nextSibling && x.nextSibling.tagName)
				{
					next = x.nextSibling.tagName.toUpperCase();
				}
				else
				{
					return;
				}
			}
		}
	}

function getCheckText(element)
{
	text = "";
	try
	{
		var td = document.createElement("td"); 
		td.appendChild(element.nextSibling);
		text = td.innerText;
	}catch(e){}
	return text;
}

function formatcheck(obj)
{
	var name = obj.name;
	var element = document.getElementById(name.substring(2));
	list = document.getElementsByTagName("INPUT");
	var val = ",";
	for(var i=0;i<list.length;i++)
	{
		if(list[i].checked && list[i].name==name)
		{
			val += list[i].value + ",";
		}
	}
	if(val == ",")
	{
		val = "";
	}
	element.value = val;
}

	function beforePrint()
	{
		top.document.getElementsByTagName('frameset')[0].rows="0,0,*";
		top.document.getElementsByTagName('frameset')[1].cols="0,*";
		document.all.header.style.display="none";
		document.all.footer.style.display="none";
	}	
	function afterPrint()
	{
		top.document.getElementsByTagName('frameset')[0].rows="72,41,*";
		top.document.getElementsByTagName('frameset')[1].cols="185,*";
		document.all.header.style.display="block";
		document.all.footer.style.display="block";
	}
	function printPreview()
	{
		beforePrint();
		document.all.WebPrinter.ExecWB(7,1);
		afterPrint();
	}
	
	function printPage()
	{
		beforePrint();
		document.all.WebPrinter.ExecWB(6,6);
		afterPrint();
	}

	function printSetup()
	{
		document.all.WebPrinter.ExecWB(8,1);
	}

    function initRequired(form) 
    {
        var i = 0;
        var fields = new Array();
        var formName = form.getAttributeNode("name");
        var oRequired;
		try
		{
		    oRequired = eval('new ' + formName.value + '_required()');
		}
		catch(e){}    
		if(!oRequired)
		{
			return;
		}
        for (x in oRequired) 
        {
            var field = form[oRequired[x][0]];
			
            if(!field || field.disabled)
            {
            	continue;
            }

			
            if(field.type == "hidden" && form["c_" + field.name])
            {
            	try
            	{
	            	var p = form["c_" + field.name][0].parentNode;
	            	while(p.parentNode.tagName!="TD")
	            	{
	            		p = p.parentNode;

	            	}
	            	if(p.parentNode.previousSibling.innerHTML.toLowerCase().indexOf("<font color=red>*</font>")<0)
	            	{
	            		p.parentNode.previousSibling.innerHTML = p.parentNode.previousSibling.innerHTML + "<font color=red>*</font>";
	            	}
	            }
	            catch(e){}
            }
            else
            {
             	try
            	{
            		if(field.length && field.length>0 && field[0].tagName=="INPUT")
	            	{
	            		field = field[0];
	            	}
	            	if(field.parentNode.previousSibling.innerHTML.toLowerCase().indexOf("<font color=red>*</font>")<0)
	            	{
            			field.parentNode.previousSibling.innerHTML = field.parentNode.previousSibling.innerHTML + "<font color=red>*</font>";
            		}
            	}
            	catch(e){}
            }
     	}
     	setMaxLength(form);
    }
    
    
	function initFieldValue(s) 
    {
    	if(!document.all("page_type")|| document.all("page_type")=="edit")
    	{
    	//	return;
    	}
    	var form = document.forms[0];
    	var arr = s.split(/[;=]/);

        for(var i = 0;i<arr.length-1;i+=2)
        {
        	try
        	{
        		if(!form[arr[i]].tagName && form[arr[i]].length>1)
        		{
        			for(var j=0;j<form[arr[i]].length;j++)
        			{
        				if(form[arr[i]][j].value == arr[i+1])
        				{
        					form[arr[i]][j].checked = true;
        				}
        			}
        		}
        		else
        		{	
        			form[arr[i]].value = arr[i+1];
        		}
        	}
        	catch(e){}
        }
     }

	function checkSelect(s)
	{
		var arr = document.getElementsByTagName("INPUT");
		for(var i = 0;i<arr.length;i++)
		{
			try
			{
				if((!s || arr[i].name==s) && arr[i].checked)
				{
					return true;
				}
			}
			catch(e){};
		}
		return false;
	}
	
	function selectAll(s)
	{
		if(!$("state_for_select"))
		{
			var s1 = "<input type='hidden' name='state_for_select' value='1'>";
			var t = document.createElement(s1);
			document.forms[0].appendChild(t);
		}
		var value = $F("state_for_select");
		if(value=="1")
		{
			$("state_for_select").value = 0;
		}
		else
		{
			$("state_for_select").value = 1;
		}
		var arr = document.getElementsByTagName("INPUT");
		for(var i = 0;i<arr.length;i++)
		{
			try
			{
				if(!s || arr[i].name==s)
				{
					if(value == "1")
					{
						arr[i].checked = true;
					}
					else
					{
						arr[i].checked = false;
					}
				}
			}
			catch(e){};
		}
	}
	
	function SelectGRList(kjmc,returnItem,returnInputItem,id,dyid)
	{
		getOptionList("../../../public/dictionary/dictionaryTreeOrList.do?method=treeOrList&XT_TYKJ_KJMC="+kjmc+"&returnList="+returnItem+"&returnInputList="+returnInputItem+"&CONDITION="+id+" = %27"+dyid+"%27");
	}
	
	function SelectDWList(kjmc,returnItem,returnInputItem,id,dyid)
	{
	    getOptionList("../../../public/dictionary/dictionaryTreeOrList.do?method=treeOrList&XT_TYKJ_KJMC="+kjmc+"&returnList="+returnItem+"&returnInputList="+returnInputItem+"&CONDITION=(instr("+id+",'"+dyid+"')>0 or '"+dyid+"' is null)");
	}
	
	function setOrigin(InputItem)
	{
		var list = InputItem.split(/[,]/);
		for(var i=0; i<list.length; i++)
		{
			try
			{
				$(list[i]).origin = $(list[i]).value;
			}catch(e){}
		}
	}
	
	function pbuttonDisable()
	{
		var list = document.getElementsByTagName("A");
		for(var i=list.length-1; i>=0; i--)
		{
			if(list[i].className == "pbutton_href")
			{
				var s = list[i].outerHTML
				var p = list[i].parentNode;
				p.removeChild(list[i]);
				p.innerHTML = s.replace("<A","<DIV").replace("</A>","</DIV>");			
			}
		}
	}
	
	function pbuttonEnable()
	{
		var list = document.getElementsByTagName("DIV");
		document.cookie = "token_cookie=" + getCookie("token_cookie").substring(5);
		for(var i=list.length-1; i>=0; i--)
		{
			if(list[i].className == "pbutton_href")
			{
				var s = list[i].outerHTML
				var p = list[i].parentNode;
				p.removeChild(list[i]);
				p.innerHTML = s.replace("<DIV","<A").replace("</DIV>","</A>");				
			}
		}
	}
	
	function resetForm(form)
	{
		pbuttonDisable();
		form = $(form);
		var value = "";
		var list = document.getElementsByTagName("SELECT");

		for(var i=0; i<list.length; i++)
		{
			if(list[i].origin)
			{
				value += list[i].name + "=" + list[i].origin + ";";
			}
		}

		form.reset();
		if(value.length>0)
		{
			
			var arr = value.split(/[=;]/);
			for(var i=0; i<arr.length; i+=2)
			{
				$(arr[i]).value = $(arr[i]).origin = arr[i+1];
			}
		}
		
		for(var i=0; i<form.elements.length; i++)
		{
			if(form.elements[i].type=="hidden" && $("c_" + form.elements[i].name))
			{
				formatcheck($("c_" + form.elements[i].name));
			}
		}
		setMaxLength(form);
		pbuttonEnable();
	}

	function getNextDay(today)
	{
		return getNextNDay(today,1);
	}
	
	function getPrevDay(today)
	{
		return getPrevNDay(today,1);
	}
	
		function getPrevNDay(today,n)
	{
		var days = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
		var year = parseInt(today.substring(0,4),10);
		var month = parseInt(today.substring(5,7),10);
		var day = parseInt(today.substring(8),10);
		var next = 1;
		if(n)
		{
		 	next = parseInt(n,10);
		}
		if(year%4==0)
		{
			days[2] = 29;
		}
		while(next>0)
		{
			if(next>=day)
			{
				next -= day;
				month--;
				if(month==0)
				{
					year--;
					if(year%4==0)
					{
						days[2] = 29;
					}
					else
					{
						days[2] = 28;
					}
					month = 12;
				}
				day = days[month];
			}
			else
			{
				day -= next;
				next = 0;
			}
		}
		return toDateValue(year) + "-" + toDateValue(month) + "-" + toDateValue(day);
	}
	function getNextNDay(today,n)
	{
		var days = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
		var year = parseInt(today.substring(0,4),10);
		var month = parseInt(today.substring(5,7),10);
		var day = parseInt(today.substring(8),10);
		var next = 1;
		if(n)
		{
		 	next = parseInt(n,10);
		}
		if(year%4==0)
		{
			days[2] = 29;
		}
		while(next>0)
		{
			if(next>days[month]-day)
			{
				next -= days[month]-day+1;
				day = 1;
				month++;
				if(month>12)
				{
					year++;
					
					if(year%4==0)
					{
						days[2] = 29;
					}
					else
					{
						days[2] = 28;
					}
					month = 1;
				}
			}
			else
			{
				day += next;
				next = 0;
			}
		}
		return toDateValue(year) + "-" + toDateValue(month) + "-" + toDateValue(day);
	}
	
	function toDateValue(i){
		var num = parseInt(i,10);
		if(num < 10){
			return "0"+num;
		}
		return num;
	}

	function setMaxLength(form)
	{
		form = $(form);
		var formName = form.getAttributeNode("name"); 

		try
		{
        	oMaxLength = eval('new ' + formName.value + '_maxlength()'); 
   		}
   		catch(e)
   		{
   			return;
   		}
        if(!oMaxLength)
        {
        	return;
        }    
        for (x in oMaxLength) 
        {
            var field = form[oMaxLength[x][0]];
            if(!field)
            {
            	continue;
            }
            try
            {
            	field.maxLength = oMaxLength[x][2]("maxlength");
            	if(field.tagName.toLowerCase()=="textarea")
            	{
            		new TextMaxLength(field);
            	}
            }
            catch(e){}
         }
     }    
     
     
function display(id) {
	if (document.layers) {
		document.layers[id].display = (document.layers[id].display != 'block') ? 'block' : 'none';
	} else if (document.all) {
		document.all[id].style.display = (document.all[id].style.display != 'block') ? 'block'	: 'none';
	} else if (document.getElementById) {
		document.getElementById(id).style.display = (document.getElementById(id).style.display != 'block') ? 'block' : 'none';
	}
}    
function getIntValue(element)
{
	var n1 = parseInt($F(element))
	if(isNaN(n1))
	{
		n1 = 0;
	}
	return n1;
}

function reValueCheck()
{
	element = event.srcElement;
	try
	{
		if(element.type=='checkbox')
		{
			element.checked = !element.checked;

		}
		else if(element.type=="radio")
		{
			list = getInputSelector(element.name);
			{
				//only for two radio,
				for(var i=0; i<list.length; i++)
				{
					list[i].checked = list[i].origin;	
				}
			}
		}	
		else if(element.tagName.toLowerCase()=="select")
		{
			if(element.origin.length>0)
			{
				element.value = element.origin;
			}
			else
			{
				element.selectedIndex = 0;
			}
		}
	}catch(e){}
}

TextMaxLength = Class.create();
TextMaxLength.prototype = {
	initialize:function(element,maxLength)
	{
		element = $(element)
		if(maxLength)
		{
			element.maxLength = isNaN(maxLength)?0:parseInt(maxLength,10);
		}
		element.onkeypress = this.doKeypress;
		element.onbeforepaste = this.doBeforePaste;
		element.onpaste = this.doPaste;
		element.onchange = this.doChange;
	},
  	doKeypress: function() {
  		//element = Event.srcElement;
		maxLength = parseInt(this.maxLength); 
		var oTR = this.document.selection.createRange(); 
		// Allow user to type character if at least one character is selected 
		if(oTR.text.length >= 1) 
			event.returnValue = true; 
		else if(this.value.length > maxLength-1) 
			event.returnValue = false; 
	},
	doBeforePaste:function(){ 
		if(this.value.length>maxLength)
			event.returnValue = false; 
	},
	doPaste:function()
	{ 
		event.returnValue = false; 
		var maxLength = parseInt(this.maxLength); 
		var oTR = this.document.selection.createRange(); 
		var iInsertLength = maxLength - this.value.length + oTR.text.length; 
		var sData = window.clipboardData.getData("Text").substr(0,iInsertLength); 
		oTR.text = sData; 
	}, 
	doChange:function()
	{ 
		maxLength = parseInt(this.maxLength); 
		if(this.value.length>maxLength)
		{
			this.value = this.value.substring(0,maxLength);
		}
	}, 	
	strlen:function(str)
	{	var i;
		var len;
		len = 0;
		for (i=0;i<str.length;i++)
		{
			if (str.charCodeAt(i)>255) len+=2; else len++;
		}
		return len;
	}
};


function deleteElement(element){
	var ele = element.split(/[,]/);
	try{
	
	for(i=0; i<ele.length; i++){
			var arr = ele[i];
			$(ele[i]).outerHTML = '';
	}
	}catch(e){}
}


function setOriginSelect(InputItem){
		var list = InputItem.split(/[,]/);
		for(var i=0; i<list.length; i++)
		{
			try
			{
				$(list[i]).originSelect = $(list[i]).value;
				$(list[i]).onchange = reValueSelect;
			}catch(e){}
		}
	}
	
function reValueSelect()
{
	
	element = event.srcElement;
	try
	{
	    if(element.tagName.toLowerCase()=="select")
		{
			if(element.originSelect.length>0)
			{
				element.value = element.originSelect;
			}
			else
			{
				element.selectedIndex = 0;
			}
		}
	}catch(e){}
}

function getToday(){
	var date = new Date();
	return date.getYear()+"-"+toDateValue(date.getMonth()+1)+"-"+toDateValue(date.getDate());
}